$import('ArrayUtil');
var BeanUtil = {
	/**
	 * 拷贝参数
	 */
	copyProperty:function(src,target,paramArray){
		var singleCopy = function(src,target,methodName){
			if(!methodName) return;
			var setMethod = target['set'
				+methodName.substring(0,1).toUpperCase()
				+methodName.substring(1,methodName.length)];
			if(setMethod){
				setMethod.apply(target,[src[methodName]]);
			}else{
				target[methodName] = src[methodName];
			}
		}
		if(!src || !target) return;
		if(paramArray){
			ArrayUtil.foreach(paramArray,
				function(n,pojo){
					singleCopy(src,target,pojo);
				}
			)
		}else{
			for(var e  in src){
				singleCopy(src,target,e); 
			}
		}
	},
	delegate:function(src,target,paramArray){
		if(src && target){
			ArrayUtil.foreach(paramArray,function(n,pojo){
				if(src[pojo]){
					target[pojo]=function(){
						return src[pojo].apply(src,arguments );
					}
				}
			});
				
		}	
	
	},
	objToString:function(o){
		var r = [];
		if (typeof o == "string") {
			return "\'" + o.replace(/([\'\"\\])/g, "\\$1").replace(/(\n)/g, "\\n").replace(/(\r)/g, "\\r").replace(/(\t)/g, "\\t") + "\'";
		}			//这里转义必须以单引号\'存在，因为双引在如"'{text:"",val:1}'"存在于事件方法中会报错
		if (typeof o == "object") {
			if (!o.sort) {
				for (var i in o) {
					r.push(i + ":" + arguments.callee(o[i]));
				}
				if ( !! document.all && !/^\n?function\s*toString\(\)\s*\{\n?\s*\[native code\]\n?\s*\}\n?\s*$/.test(o.toString)) {
					r.push("toString:" + o.toString.toString());
				}
				r = "{" + r.join() + "}"
			} else {
				for (var i = 0; i < o.length; i++) {
					r.push(arguments.callee(o[i]))
				}
				r = "[" + r.join() + "]"
			}
			return r;
		}
		return "" + o;
	},
	hashCode:function(str){
		if(str==null || str=="") return 0;
		str=str.toString();
		var len = str.length;
		var sum = 0;
		for(var i=0;i<len;i++){
			sum += str.charCodeAt(i)*Math.pow(31,len-1-i);
		}
		return sum.toString();
	}
}